package com.job.project.config;

import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executor;

/**
 * @Author 王博
 * @DateTime 2024-07-04 14:27
 */
@Component
public class MyThreadPoolAsyncConfigurer implements AsyncConfigurer {
    @Override
    public Executor getAsyncExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5); // 核心线程数
        executor.setMaxPoolSize(10); // 最大线程数
        executor.setQueueCapacity(25); // 队列大小
        executor.setThreadGroupName("自定义线程池");
        executor.setThreadNamePrefix("my-");
        executor.initialize();
        return executor;
    }
}
